﻿@model IEnumerable<LanDBom.Models.parice>
@using LanDBom.Models
@using LanDBom.Resources
@{
    ViewBag.Title = "Index";
}
<style>
    .YCFile {
        display: none;
        background-color: #fff;
        width: 350px;
        height: 150px;
        position: absolute;
        left: 22%;
        top: 40%;
    }
    .YANds {
        display: flex;
        align-items: center;
        justify-content: space-between;
        background-color: #0866a563;
        border-radius: 8px;
        margin: 3px 4px;
        padding: 2px 10px;
    }
</style>
<h2>@Resource.String254</h2>

<form class="row padtop col-12" action="#" method="post">
    <fieldset class="boun">
        <legend class="len">查询条件</legend>
        <div class="row">
            <p class="col">
                @Html.Label(Resource.String255)
                @Html.TextBox("pp", "", new { @class = "input-au" })
            </p>
            <p class="col">
                @Html.Label(Resource.String256)
                <select id="ming" name="ming" class="input-au">
                    <option value=""></option>
                    @foreach (var item in ViewBag.fenlei as List<mateial>)
                    {
                        if (@item.MA_fne != "彩印")
                        {
                            <option value="@item.MA_ID">@item.MA_fne</option>
                        }
                    }
                </select>
            </p>
            <p class="col">
                @Html.Label(Resource.String804)
                @Html.TextBox("Zhisnd", "", new { @class = "input-au" })
            </p>
            <p class="col">
                @Html.Label(Resource.String803)
                <input type="number"  id="shi" name="shi" value="" class="input-au"/>
            </p>
            <p class="col-2">
                <input type="submit" value="查询" name="cha" class=" btn-secondary btn-sm" />
            </p>
        </div>
    </fieldset>
</form>
<p>
    @Html.ActionLink(Resource.String258, "Create", null, new { @class = "btn" })
    <input type="button" value="批量上传" id="zhankai" class = "btn"/>
</p>
<div style="display:none" id="xianshi">
    <input type="button" name="name" value="下载文件" id="BB_WT_scbb"/>
    <input type="button" name="name" value="上传文件" id="btn_chuan"/>
</div>
<div id="tinajia" class="YCFile">
    <div class="YANds"><span>@Resource.String108</span><span><i class="bi bi-x-circle" id="Quxiao"></i></span></div>
    <div class="SHnacs">
        <input type="file" value="" id="SHanngcF" accept="" />
        <input type="button" value="@Resource.String108" id="TIjaio" />
    </div>
</div>
<div id="WT_dh_mb2" style="display: none; position: absolute; border: 1px black solid; left: 25%; top: 33%; background-color: white; background-color: #f1f1f1;height:200px;width:300px">
    <div style="text-align: right; background-color: #84acde;"><span class="WT_qxbh2" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
    <div style="margin: 20px 10px; padding: 10px; background-color: #fff;">
        <div id="WJ_XZLJ"></div>
    </div>
    <div style="text-align:center"><button class="WT_qxbh2">@Resource.String126</button></div>
</div>
<table class="tab table">
    <thead class="thead-light">
        <tr style="text-align-last:center;">
            <th>
                @Html.Label(Resource.String259)
            </th>
            <th>
                @Html.Label(Resource.String260)
            </th>
            <th>
                @Html.Label(Resource.String261)
            </th>
            <th>
                @Html.Label(Resource.String262)
            </th>
            <th>
                @Html.Label(Resource.String263)
            </th>
            <th>
                @Html.Label(Resource.String264)
            </th>
            <th>
                @Html.Label(Resource.String265)
            </th>

            <th>
                @Html.Label(Resource.String266)
            </th>

        </tr>
    </thead>
    <tbody style="height:420px;" id="BUtain">
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.PA_Pinpai)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.PA_ZhongL)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.PA_KZ)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.PA_T)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.PA_Time)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.PA_LengBie)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.mateial.MA_fne)
                </td>
                @if (MyAuthentication.IsLogin())
                {
                    if (MyAuthentication.GetUsers().DE_quan == "管理员"|| MyAuthentication.GetUsers().DE_shenfen ==6 || MyAuthentication.GetUsers().DE_shenfen == 7)
                    {
                        <td>
                            @Html.ActionLink(Resource.String232, "Edit", new { id = item.PA_ID }) |
                            @Html.ActionLink(Resource.String223, "Delete", new { id = item.PA_ID })
                        </td>
                    }
                    else
                    {
                        <td>@Resource.String257</td>
                    }
                }
                else
                {
                    <td>@Resource.String258</td>
                }
            </tr>
        }
    </tbody>
</table>
<div style="display: flex; justify-content: space-between;">
    <span>共 @ViewBag.Yeshu 行</span>
    @using (Html.BeginForm("Cliview", "Application", FormMethod.Post))
    {<nav aria-label="Page navigation example" class="row" style="margin-right:50px;">
            <ul class="pagination">
            </ul>
            共<span id="komdr">@ViewBag.Shund</span>页
        </nav>
    }
</div>
@section scripts{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            $("#li21").css({ "color": "black", "background-color": "white" })
            var now = new Date($.now());
            //获取当前年月日
            var year = (now.getFullYear()).toString();
            var month = (now.getMonth() + 1).toString();
            var date = (now.getDate()).toString();
            var qishi_time2 = year + "/" + month + "/" + date
            $("#PA_Time").val(qishi_time2)
            $("#PA_Time").prop('disabled', true)

            //分页
            $(document).ready(function () {
                var sjnd = "1"
                fenye(sjnd)
            })
            function fenye(a) {
                var hjin = a * 1
                var shunddd = $("#komdr").text() * 1+1
                $(".pagination li").remove()
                var $ul = ""
                $ul += (`<li class="page-item"><span class="page-link shiyong"><<<</span></li>`)
                for (var i = 1; i <= shunddd; i++) {
                    if (a < 4) {
                        if (i < 5) {
                            $ul += "<li class='page-item'><span class='page-link shiyong'>" + i + "</span></li>";
                        } else {
                            $ul += "<li class='page-item'><span class='page-link'>.....</span></li>";
                            break
                        }
                    }
                    if (a >= 4) {
                        console.log(i, a, hjin, hjin - 2, hjin + 2, shunddd)
                        if (i < (hjin - 2)) {
                            continue
                        }
                        if (i > (hjin - 2) && i < (hjin + 2)) {
                            $ul += "<li class='page-item'><span class='page-link shiyong'>" + i + "</span></li>";
                        } else {
                            $ul += "<li class='page-item'><span class='page-link'>.....</span></li>";
                        }
                        if (i >= (hjin + 2)) {
                            break
                        }
                    }

                }
                $ul += (`<li class="page-item"><span class="page-link shiyong">>>></span></li>`);
                $(".pagination").append($ul)
            }
            $(document).on("click", ".shiyong", function () {
                var shunddd = $("#komdr").text()
                var sjind = $(this).text()
                sjind = sjind == "<<<" ? "1" : sjind == ">>>" ? shunddd : sjind
                fenye(sjind)
                $.ajax({
                    url: '/parices/Index',
                    type: 'POST',
                    data: { "shund": sjind, "state": 1 },
                    success: function (date) {
                        createRow(date)
                    },
                    error: function (date) {
                        alert(date);
                    }
                })
            })
            function createRow(date) {
                $("#BUtain tr").remove();
                var indec = 1
                $.each(date, function (i, item) {
                    var idsw = item.PA_ID
                    var $tr = (`<tr><td>${item.PA_Pinpai}</td><td>${item.PA_ZhongL}</td><td>${item.PA_KZ}</td><td>${item.PA_T}</td><td>${item.PA_Time}</td><td>${item.PA_LengBie}</td><td>${item.MA_fne}</td>
                     @if (MyAuthentication.IsLogin())
                {
                    if (MyAuthentication.GetUsers().DE_quan == "管理员")
                    {
                        <td>
                           <a href="/parices/Edit?id=${idsw}">@Resource.String232</a>|<a href="/parices/Delete?id=${idsw}">@Resource.String223</a>
                        </td>
                    }
                    else
                    {
                        <td>@Resource.String257</td>
                    }
                }
                else
                {
                    <td>@Resource.String258</td>
                }
                    </tr>`);
                    $("#BUtain").append($tr);
                    indec++
                })
            }
            $(document).on("click", "#btn_chuan", function (e) {
                $("#tinajia").css({ "display": "block" })
            })
            //关闭文件上传
            $(document).on("click", "#Quxiao", function () {
                $("#tinajia").css({ "display": "none" })
            })
            $(document).on("click", "#zhankai", function () {
                $("#xianshi").toggle()
            })
            //提交文件
            $("#TIjaio").click(function () {
                var fileUpload = $('#SHanngcF')[0];
                if (fileUpload.files.length > 0) {
                    var formData = new FormData();
                    formData.append('file', fileUpload.files[0]);
                    console.log(formData)
                    $.ajax({
                        url: '/Material/Yuanpl',
                        type: 'POST',
                        data: formData,
                        processData: false,		//用于对data参数进行序列化处理 这里必须false
                        contentType: false,
                        success: function (fgggh) {
                            console.log(fgggh)
                            if (fgggh.length == 0) {
                                alert("该文件已打开，请关闭后重试！")
                            } else {
                                alert(fgggh)
                                location.reload()
                                $("#tinajia").hide()
                            }
                        },
                        error: function (xhr) {
                            alert("系统错误" + xhr);
                        }
                    })
                } else {
                    alert('请选择要上传的文件！');
                }
            })
            //下载文件
            $(document).on("click", "#BB_WT_scbb", function () {
                $.ajax({
                    url: "/Material/DownloadExcel2",
                    type: 'POST',
                    data: {  "state": 1 },
                    success: function (text) {
                        $("#WT_dh_mb2").css({ "display": "block" })
                        $("#WJ_XZLJ").append($(`<a href="/Contracts/Download_file?path=${text}" id="log_SZ" class="WT_qxbh2">下载</a>`))
                    },
                    error: function (text) {
                        alert("系统错误");
                    }
                })
            })
            $(document).on("click", ".WT_qxbh2", function () {
                $("#WT_dh_mb2").css({ "display": "none" })
                $("#WJ_XZLJ a").remove()
            })
        })
    </script>
}